
public class GMM {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		//mu, sigma, pi
		double[][] gaussPlus = new double[][]{
		{-2.9874,0.0625,0.079669335223781},
		{-1.57,0.4552,0.38370471454542},
		{0.0,0.6673,0.073251900461598},
		{1.57,0.4522,0.38370471454542},
		{2.9874,0.0625,0.079669335223781}
	};
		
		double[][] gaussMinus = new double[][]{
		{-2.6613,0.0956,0.12979434811066548},
		{-1.4209,0.4670,0.310697919200458},
		{0.0262,0.1257,0.12953879776828747},
		{1.2555,0.3050,0.23531019352693014},
		{2.5254,0.1493,0.194658741393659},
		};
		
		if (args.length>0){
			double x = Double.parseDouble(args[0]);
			if (x >= -Math.PI && x <= Math.PI) {
				double valuePlus = 0;
				double normal = 0;
				for (int i = 0; i < 5; i++) {
					normal = normalDens(x, gaussPlus[i][0], gaussPlus[i][1]) * gaussPlus[i][2];
					valuePlus = valuePlus + normal;
				}
				double valueMinus = 0;
				for (int i = 0; i < 5; i++) {
					normal = normalDens(x, gaussMinus[i][0], gaussMinus[i][1]) * gaussMinus[i][2];
					valueMinus = valueMinus + normal;
				}
				System.out.println("In Konversation:"+valuePlus);
				System.out.println("Nicht in Konversation:"+valueMinus);
				Charts charts = new Charts("Test", new double[]{valuePlus, valueMinus});
				charts.start();

			} else {
				System.out
						.println("Bitte einen Wert zwischen -pi und pi eingeben.");
			}			
		}
		else{
			System.out.println("Bitte einen Wert zwischen -pi und pi eingeben.");
		}
	}
	/**
	 *   The aim of this static method is to implememnt the function of Gaussian distribution
	 *   N（μ，σ2)
	 * @param x   variable
	 * @param mean   mathematic expectation
	 * @param stdDev Variance
	 * @return
	 */
	public static double normalDens(double x, double mean, double stdDev) {
	     double diff = x - mean;
	     return (1 / ( Math.sqrt(2 * Math.PI) * stdDev))
	             * Math.exp(-(diff * diff / (2 * stdDev * stdDev)));
	 }
}
